package servlet;

import com.alibaba.fastjson.JSON;
import utils.BaseDao;
import utils.BaseModel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "selectMessageServlet",urlPatterns = {"/SelectMessage"})
public class selectMessageServlet extends HttpServlet {
    BaseDao baseDao=new BaseDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sql="select * from t_message a left join t_user b on a.user_id=b.user_id";
        List list=baseDao.query(sql,null);
        BaseModel baseModel=new BaseModel();
        baseModel.setCode(1);
        baseModel.setMessage("查询用户信息成功");
        baseModel.setData(list);
        String baseModelStr=JSON.toJSONString(baseModel);
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(baseModelStr);
        resp.getWriter().flush();
        resp.getWriter().close();
    }
}
